package com.lk.sys.common.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

@Component
@Aspect
@Slf4j
public class SysExceptionAspect {
    /**
     * 可以记录异常信息，但不会截断，还是会继续抛出给调用者
     * @author Lukang
     * @date 2022/1/9 下午9:51
     * @param e
     */
    @AfterThrowing(value = "bean(sysUserServiceImpl)", throwing = "e")
    public void doLogException(JoinPoint joinPoint, Exception e) {
        //获取目标方法签名
        MethodSignature ms = (MethodSignature) joinPoint.getSignature();
        //String methodName = ms.getDeclaringType() + "." + ms.getName();
        Class<?> targetClass = joinPoint.getTarget().getClass();
        String targetMethodName = targetClass.getName() + "." + ms.getName();
        log.error("SysExceptionAspect --> {}'s Exception is {}", targetMethodName, e.getMessage());
    }

}
